package com.study.spring.ch03.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.study.spring.ch03.pojo.Student;
import com.study.spring.ch03.pojo.Teacher;

@Controller
@RequestMapping(value = "/ch03/multiModel/**") // ①处理器的通用映射前缀
public class MultiModelController {

	@InitBinder("stu")
	public void initBinderStudent(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("stu.");
	}

	@InitBinder("teacher")
	public void initBinderTeacher(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("teacher.");
	}

	/**
	 * http://×××/ch03/params/abc?create
	 * 
	 * @return
	 */
	@RequestMapping(value = "show", method = RequestMethod.GET)
	public String showForm() {
		System.out.println("================showForm");
		return "ch03/multiModel";
	}


	/**
	 * URL“http://×××/parameter1?create
	 * 
	 * @return
	 */
	@RequestMapping(value = "submit", method = RequestMethod.POST)
	public String submit(@ModelAttribute("stu") Student um
			, @ModelAttribute("teacher") Teacher dm) {
		System.out.println("================submit");
		return "ch03/success";
	}

}
